﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Clipper.Model;
using System.Threading;
using System.ComponentModel;
using Communication;

namespace Clipper.BLL.DetectChain.AddR1AndSample
{
    public class R1SampleHelper
    {
        /// <summary>
        /// 一种试剂1的检测
        /// </summary>
        static CupComponent OneReagent1 = null;
        /// <summary>
        /// 两个试剂1的检测，稀释液
        /// </summary>
        static CupComponent TwoReagent1 = null;


        public static ArmControl armSample = null;

        public static ArmControl armR1 = null;

        /// <summary>
        /// 生成检测流程
        /// </summary>
        /// <returns></returns>
        public static void InitDetectChain()
        {
            KitA kitA = new KitA();
            ArmReagent1 armReagent1 = new ArmReagent1();
            ArmSample armSample = new ArmSample();

            kitA.NextComponent = armReagent1;
            armReagent1.NextComponent = armSample;

            OneReagent1 = kitA;


        }
        /// <summary>
        /// 运行
        /// </summary>
        /// <param name="cup"></param>
        public static void RunCup(Model.ReactionStrip strip)
        {
            foreach (ReactionCup cup in strip.ReactionCupList)
            {
                while (true)
                {
                    if (OneReagent1.DetectionStatus == ControlStatusEnum.IDLE &&
                    OneReagent1.NextComponent.DetectionStatus == ControlStatusEnum.IDLE)
                        break;
                    else
                        Thread.Sleep(100);
                }
                OneReagent1.DetectionStatus = ControlStatusEnum.BUSY;
                BackgroundWorker back = new BackgroundWorker();
                back.DoWork += (ss, ee) =>
                {
                    
                    OneReagent1.Run(cup);
                };
                back.RunWorkerAsync();
            }
        }
    }
}
